<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php /* @var $block \Magento\Downloadable\Block\Catalog\Product\Links */ ?>
<?php $_linksPurchasedSeparately = $block->getLinksPurchasedSeparately(); ?>
<?php if ($block->getProduct()->isSaleable() && $block->hasLinks()):?>
    <?php $_links = $block->getLinks(); ?>
    <?php $_linksLength = 0; ?>
    <?php $_isRequired = $block->getLinkSelectionRequired(); ?>
    <legend class="legend links-title"><span><?= $block->escapeHtml($block->getLinksTitle()) ?></span></legend><br>
    <div class="field downloads<?php if ($_isRequired) echo ' required' ?><?php if (!$_linksPurchasedSeparately) echo ' downloads-no-separately' ?>">
        <label class="label"><span><?= $block->escapeHtml($block->getLinksTitle()) ?></span></label>
        <div class="control" id="downloadable-links-list"
             data-mage-init='{"downloadable":{
                 "linkElement":"input:checkbox[value]",
                 "allElements":"#links_all",
                 "config":<?php /* @escapeNotVerified */ echo $block->getJsonConfig() ?>}
             }'
             data-container-for="downloadable-links">
            <?php foreach ($_links as $_link): ?>
                <?php $_linksLength++;?>
                <div class="field choice" data-role="link">
                    <?php if ($_linksPurchasedSeparately): ?>
                        <input type="checkbox"
                               <?php if ($_isRequired): ?>data-validate="{'validate-one-checkbox-required-by-name':'downloadable-links-list'}" <?php endif; ?>
                               name="links[]"
                               id="links_<?php /* @escapeNotVerified */ echo $_link->getId() ?>"
                               value="<?php /* @escapeNotVerified */ echo $_link->getId(); ?>" <?php /* @escapeNotVerified */ echo $block->getLinkCheckedValue($_link); ?> />
                    <?php endif; ?>
                    <label class="label" for="links_<?php /* @escapeNotVerified */ echo $_link->getId() ?>">
                        <span><?php echo $block->escapeHtml($_link->getTitle()); ?></span>
                        <?php if ($_link->getSampleFile() || $_link->getSampleUrl()): ?>
                            <a class="sample link"
                               href="<?= /* @escapeNotVerified */ $block->escapeQuote($block->getLinkSampleUrl($_link)) ?>" <?php echo $block->getIsOpenInNewWindow() ? 'target="_blank"' : ''; ?>>
                                <?php /* @escapeNotVerified */ echo __('sample') ?>
                            </a>
                        <?php endif; ?>
                        <?php if ($_linksPurchasedSeparately): ?>
                            <?php /* @escapeNotVerified */ echo $block->getLinkPrice($_link); ?>
                        <?php endif; ?>
                    </label>
                </div>
            <?php endforeach; ?>
            <?php if ($_linksPurchasedSeparately && $_linksLength > 1): ?>
                <div class="field choice downloads-all">
                    <input type="checkbox"
                           data-notchecked="<?php /* @escapeNotVerified */ echo __('Select all')?>"
                           data-checked="<?php /* @escapeNotVerified */ echo __('Unselect all')?>"
                           id="links_all" />
                    <label class="label" for="links_all"><span><?php /* @escapeNotVerified */ echo __('Select all')?></span></label>
                </div>
            <?php endif; ?>
        </div>
        <?php if ($_isRequired): ?>
            <span id="links-advice-container"></span>
        <?php endif;?>
    </div>
<?php endif; ?>
